package groupb6.shopsystem.util.response;

import groupb6.shopsystem.util.enums.ResponseEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
public class UniversalResponse<T> {
    @ApiModelProperty("状态代码")
    private Integer code;
    @ApiModelProperty("信息")
    private String msg;
    @ApiModelProperty("数据（仅存在于1000状态中）")
    private T data;

    public UniversalResponse() {
    }

    public UniversalResponse(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = null;
    }

    public UniversalResponse(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public UniversalResponse<T> ok(T data) {
        this.code = ResponseEnum.SUCCESS.getCode();
        this.msg = ResponseEnum.SUCCESS.getMsg();
        this.data = data;
        return this;
    }
    public UniversalResponse<T> ok() {
        this.code = ResponseEnum.SUCCESS.getCode();
        this.msg = ResponseEnum.SUCCESS.getMsg();
        this.data = null;
        return this;
    }

}
